<template>
<view class="flx_cenetr_content_container">
    <view class="flx_cenetr_content_title">主人~该卡券已分享{{List.length}}次</view>

     
    <block v-if="List.length==0">
      <view class="none">
        <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
        <text>该卡券还未分享~</text>
      </view>
    </block>

    <view v-else class="flx_user_container">
      <view class="flx_user_item" v-for="(item, index) in List" :key="index">
        <view class="info_left">
          <!-- <view class="user_head">
            <image class="user_img" :src="(item.headimgurl ? item.headimgurl : '/images/icons/me1.png')"></image>
            <text class="user_level">{{item.userLevelName}}</text>
          </view> -->
          <view class="flx_user_item_info">
            <view class="flx_user_item_head">
              <text>{{item.gainPlatformUserName}}</text>
              <view class='tg_num_info' @tap="calling(item.telNo)" v-if="item.telNo&&options.relateType=='directChildren'">
                <image class='tg_num_icon' src='https://image1.sansancloud.com/xianhua/2019_5/8/17/24/48_378.jpg?x-oss-process=style/preview_120'></image>
                <!-- <text class='tg_num'>{{item.levelOneFxUserCount}}</text> -->
              </view>
              <!-- <view class='tg_num_info'>
                <image class='tg_num_icon' src='https://image1.sansancloud.com/xianhua/2019_1/17/17/44/13_843.jpg'></image>
                <text class='tg_num'>{{item.levelOneFxUserCount}}</text>
              </view> -->
            </view>
            <view class="font_small">来自卡券：{{item.cardName}}</view>
          </view>
        </view>
        <view class="lastest_time">
          <text class="lastest_time_title">获取时间</text>
          <text class="lastest_time_value">{{item.gainTime}}</text>
        </view>
      </view>
    </view>
    


</view>
</template>

<script>

export default {
  data() {
    return {
      List: [],

      /**
       * 生命周期函数--监听页面加载
       */
      options: {},
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      }
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    this.options = options;
    this.get_fx_usersFun(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.favouriteList = [];
    this.listPage.page = 1;
    this.get_fx_usersFun(this.options);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
      that.listPage.page++;
      this.get_fx_usersFun(this.options);
    }
  },
  methods: {
    calling:function(telno){
        getApp().globalData.calling(telno)
    },
    get_fx_usersFun: function (options) {
      console.log('-------分销人--------');
      let getParam = {page:this.listPage.page};
      getParam=Object.assign({},getParam,options)
      var customIndex = getApp().globalData.AddClientUrl("/wx_find_share_card_voucher_instance_gain_list.html", getParam);
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          that.listPage.pageSize = res.data.relateObj.pageSize;
          that.listPage.curPage = res.data.relateObj.curPage;
          that.listPage.totalSize = res.data.relateObj.totalSize;
          let data = res.data.relateObj.result;
          if (!data) {
            return;
          }
          if (data.length == 0 && that.List.length == 0) {
            // that.setData({
            //   List: null
            // });
          } else {
            // 获取到的数据要添加进原先的数据
            let newList = that.List;
            if(that.listPage.page !=1){
                newList = newList.concat(res.data.relateObj.result);
            }else{
                newList=res.data.relateObj.result
            }
            console.log(newList);

            for (let i = 0; i < newList.length; i++) {
              newList[i].gainTime = newList[i].gainTime.slice(0, -9);
            }

            that.setData({
              List: newList
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>